package com.jerry.quartz.domain;

import org.apache.log4j.Logger;
import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Date;

/**
 * Created by Shirly on 2016/12/14.
 */
public class MyJob implements Job {
    Logger LOG = Logger.getLogger(this.getClass());

    public static final String DATA_TARGET_KEY ="target";
    public static final String DATA_TRIGGER_KEY ="triggerKey";
    public static final String DATA_TRIGGER_PARM_KEY ="triggerParm";
    public static final String DATA_TASK_KEY ="task";

    @Override
    public void execute(JobExecutionContext ctx) throws JobExecutionException {
       JobDataMap dataMap = ctx.getTrigger().getJobDataMap();
       Object target = dataMap.get(DATA_TARGET_KEY);
        Method method = (Method)dataMap.get(DATA_TRIGGER_KEY);
        Object[] param =(Object[])dataMap.get(DATA_TRIGGER_PARM_KEY);
        SchedluerTask task = (SchedluerTask)dataMap.get(DATA_TASK_KEY);
        try {
            method.invoke(target,param);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
